package com.dmall.jdbc.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;

import com.dmall.jdbc.bean.User;

public class DmallUserDao {

	public int insertUser(Connection conn, User user) throws Exception {
		PreparedStatement ps = null;
		try {
			String sql = "insert into dmall_user(login_name, login_password, real_name, gender, birth) values(?,?,?,?,?)";
			ps = conn.prepareStatement(sql);
			ps.setString(1, user.getLoginName());
			ps.setString(2, user.getLoginPassword());
			ps.setString(3, user.getRealName());
			ps.setInt(4, user.getGender());
			ps.setString(5, user.getBirth());
			int count = ps.executeUpdate();
			if (count <= 0) {
				throw new Exception();
			}
			return count;
		} catch (Exception e) {
			throw e;
		} finally {
			if (ps != null) {
				ps.close();
			}
		}
	}

	public void executeDDL(Connection conn, String ddl) throws Exception {
		Statement ps = null;
		try {
			ps = conn.createStatement();
			int i = ps.executeUpdate(ddl);
			System.out.println(i);
		} catch (Exception e) {
			throw e;
		} finally {
			if (ps != null) {
				ps.close();
			}
		}
	}
}
